Course materials for 2020-11-2 AFEC at XTBG.
Let’s condier maps with some environmental variables (e.g., soil N, soil moisture…).
Soil moisture (z0) are randomly distributed.
\[ \left[ \begin{array}{r} y_1 \\ y_2 \\ y_3 \\ y_4 \\ y_5 \\ y_6 \end{array} \right] = \rho \left[ \begin{array}{rrrrrr} 0 & 1/3 & 0 & 1/3 & 1/3 & 0 \\ 1/3 & 0 &&&& \\ 0 && 0 &&& \\ 1/3 & & & 0 && \\ 1/3 & & & & 0 & \\ 0 & & & & & 0 \end{array} \right] \cdot \left[ \begin{array}{r} y_1 \\ y_2 \\ y_3 \\ y_4 \\ y_5 \\ y_6 \end{array} \right] + \epsilon \]
\[ y_1 = \rho * 1/3 (y_2 + y_4 + y_5) + \epsilon \]
In general, spatial autocorrelaiton models take this kind of form.
\[ Y = X \beta + \rho W Y + \epsilon \]
## # A tibble: 625 x 4
## x y hab trait
## <dbl> <dbl> <chr> <dbl>
## 1 1 1 ridge 2.93
## 2 2 1 valley -0.819
## 3 3 1 valley -2.28
## 4 4 1 ridge 4.99
## 5 5 1 valley -0.996
## 6 6 1 valley -0.574
## 7 7 1 ridge 1.46
## 8 8 1 ridge 0.596
## 9 9 1 ridge 1.26
## 10 10 1 ridge 1.35
## # … with 615 more rows
## Neighbour list object:
## Number of regions: 625
## Number of nonzero links: 4704
## Percentage nonzero weights: 1.204224
## Average number of links: 7.5264
## Characteristics of weights list object:
## Neighbour list object:
## Number of regions: 625
## Number of nonzero links: 4704
## Percentage nonzero weights: 1.204224
## Average number of links: 7.5264
##
## Weights style: W
## Weights constants summary:
## n nn S0 S1 S2
## W 625 390625 625 169.8933 2510.443
##
## Call: spatialreg::spautolm(formula = formula, data = data, listw = listw,
## na.action = na.action, family = family, method = method,
## verbose = verbose, trs = trs, interval = interval, zero.policy = zero.policy,
## tol.solve = tol.solve, llprof = llprof, control = control)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.9026232 -0.4330284 0.0047709 0.4380002 5.1772142
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.024362 0.094447 0.2579 0.7965
##
## Lambda: 0.60843 LR test value: 128.96 p-value: < 2.22e-16
## Numerical Hessian standard error of lambda: 0.045821
##
## Log likelihood: -857.8677
## ML residual variance (sigma squared): 0.85481, (sigma: 0.92456)
## Number of observations: 625
## Number of parameters estimated: 3
## AIC: 1721.7
lambda (rho) = 0.6084325 indicates a positve spatial autocorrelaiton
Model with an environmetal predictor
##
## Call: spatialreg::spautolm(formula = formula, data = data, listw = listw,
## na.action = na.action, family = family, method = method,
## verbose = verbose, trs = trs, interval = interval, zero.policy = zero.policy,
## tol.solve = tol.solve, llprof = llprof, control = control)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.30126 -0.41144 0.02866 0.40400 4.36665
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.702901 0.052053 13.504 < 2.2e-16
## habvalley -1.370559 0.065657 -20.875 < 2.2e-16
##
## Lambda: 0.25345 LR test value: 12.031 p-value: 0.00052329
## Numerical Hessian standard error of lambda: 0.070405
##
## Log likelihood: -717.2709
## ML residual variance (sigma squared): 0.57583, (sigma: 0.75883)
## Number of observations: 625
## Number of parameters estimated: 4
## AIC: 1442.5
habvalley indicates valley sites have negative effects on trait values compared to ridge sites even after controlling spatial autocorrelaiton.fit1$fit$residuals is a vector of \(\epsilon\).geom_violin, geom_boxplot